import store from "@/store";

export default {
  inserted(el, binding) {
    const {
      value
    } = binding;
    const tasks = store.getters && store.getters["app/userInfo"] && store.getters["app/userInfo"].tasks;
    if (tasks && value && value instanceof Array && value.length > 0) {
      const permissionTasks = value;

      const hasPermission = tasks.some(tasks => {
        return (
          permissionTasks.includes(tasks.taskCode) ||
          permissionTasks.some(per => {
            return tasks.taskCode.startsWith(per + ".");
          })
        );
      });

      if (!hasPermission) {
        el.parentNode && el.parentNode.removeChild(el);
      }
    }
  }
};
